package com.ylxn.elasticsearch;

import org.apache.http.HttpHost;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;

import java.io.IOException;

/**
 * @author: coll man
 * @create: 2021-05-17 09:49
 */
public class es_index {
    public static void main(String[] args) throws IOException {
        //创建ES客户端
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(new HttpHost("localhost",9200,"http"))
        );
        CreateIndexRequest indexRequest = new CreateIndexRequest("user233211");
        CreateIndexResponse response = client.indices().create(indexRequest, RequestOptions.DEFAULT);
        boolean b = response.isAcknowledged();
        //System.out.println("响应结果： = "+b);
        System.out.println(response);
        //关闭客户端
        client.close();
    }
}
